/*************************************************
 * 
 * Copyright by Bruno Eberhard
 * 
 * Created on 02.06.2006
 *
 *************************************************/
package fightplan.core;

import java.awt.Color;

import fightplan.business.ValueValidation;

public class NotEmptyValidation implements ValueValidation {

	private Color severityIfInvalid = RED;
	private String textIfInValid = "Darf nicht leer sein.";

	public NotEmptyValidation() {

	}

	public NotEmptyValidation(Color severityIfInvalid, String textIfInValid) {
		this.severityIfInvalid = severityIfInvalid;
		this.textIfInValid = textIfInValid;
	}

	public Color validationColor(Object validatable) {
		if (validatable instanceof String) {
			String s = (String) validatable;
			if (s == null || s.trim().length() == 0) {
				return severityIfInvalid;
			} else {
				return null;
			}
		} else if (validatable != null) {
			return YELLOW;
		} else {
			return severityIfInvalid;
		}
	}

	public String validationText(Object validatable) {
		if (validatable instanceof String) {
			String s = (String) validatable;
			if (s == null || s.trim().length() == 0) {
				return textIfInValid;
			} else {
				return null;
			}
		} else if (validatable != null) {
			return "Validierung fehlgeschlagen: " + validatable;
		} else {
			return textIfInValid;
		}

	}

}
